package com.example.security.result;

import com.example.security.constants.Code;

import java.io.Serializable;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 *

 * 自定义响应数据结构
 *
 */
@Data
@Accessors(chain = true)
public class JsonResult implements Serializable {

    private static final long serialVersionUID = 1576728571318750335L;

    /**
     * 响应业务状态
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应中的数据
     */
    private Object data;

    public static JsonResult build(String code,String message,Object data){
        return new JsonResult().setCode(code).setMessage(message).setData(data);
    }

    public static JsonResult build(Result result,Object data){
        return new JsonResult().setCode(result.getCode()).setMessage(result.getMessage()).setData(data);
    }

    public static JsonResult ok(){
        return new JsonResult().setCode(Code.OK.getCode()).setMessage(Code.OK.getMessage());
    }

    public static JsonResult ok(Object data){
        return new JsonResult().setCode(Code.OK.getCode()).setMessage(Code.OK.getMessage()).setData(data);
    }

    public static JsonResult error(){
        return new JsonResult().setCode(Code.SYSTEM_ERROR.getCode()).setMessage(Code.SYSTEM_ERROR.getMessage());
    }

    public static JsonResult error(Object data){
        return new JsonResult().setCode(Code.SYSTEM_ERROR.getCode()).setMessage(Code.SYSTEM_ERROR.getMessage()).setData(data);
    }

    public static JsonResult error(Result result){
        return new JsonResult().setCode(result.getCode()).setMessage(result.getMessage());
    }

    public static JsonResult error(Result result,Object data){
        return new JsonResult().setCode(result.getCode()).setMessage(result.getMessage()).setData(data);
    }





}
